<template>
	<view class="globe_back">
		<z-paging ref="paging" v-model="list"  v-if="type==0">
			<view class="list" v-for="(item,index) in list" @click="to_list(item.id)">
				<view class="flex justify_content_between">
					<view class="title">{{ item.trade_name }}</view>
					<u-icon name="arrow-right" size="16"></u-icon>
				</view>
				<view>
					<text class="tip">{{ item.tip }}</text>
					<text class="time">{{ item.start }}-{{ item.end }}</text>
				</view>
				<view class="flex address" @click.stop="address">
					<image class="iconImg" src="@/static/imgs/icon_dw.png" mode="widthFix"></image>
					<text class="km">{{ item.distance }}km</text>
					<text>{{ item.address }}</text>
				</view>
			</view>
		</z-paging>
		<z-paging ref="paging" v-model="list"  v-else>
			<view class="list" v-for="(item,index) in list" @click="xzsh(item)">
				<view class="flex justify_content_between">
					<view class="title">{{ item.trade_name }}</view>
					<u-icon name="arrow-right" size="16"></u-icon>
				</view>
				<view>
					<text class="tip">{{ item.tip }}</text>
					<text class="time">{{ item.start }}-{{ item.end }}</text>
				</view>
				<view class="flex address" @click.stop="address">
					<image class="iconImg" src="@/static/imgs/icon_dw.png" mode="widthFix"></image>
					<text class="km">{{ item.distance }}km</text>
					<text>{{ item.address }}</text>
				</view>
			</view>
		</z-paging>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				list: [],
				lat:'',
				lng:'',
				page:1,
				pagesize:10,
				status:'nomore',
				type:0,
			};
		},
		onLoad(e) {
			if(e.type){
				this.type=e.type
			}
			console.log(e)
			var that= this 
			uni.getLocation({
				type: 'wgs84',
				// altitude:true,
				success: function (res) {
					that.lat=res.latitude;
					that.lng=res.longitude;
				}
			});
			setTimeout(() => {
				this.de(1);
			}, 1000);
		},
		onReachBottom() {
		
		  if (this.page * this.pagesize > this.list.length) return;
		  this.status = "loading";
		  this.page = ++this.page;
		  setTimeout(() => {
		    this.de(2);
		    if (this.page * this.pagesize > this.list.length)
		      this.status = "nomore";
		    else this.status = "loading";
		  }, 1000);
		},
		methods: {
			de(e){
				console.log('当前位置的经度：');
				this.$.ajax(1,"POST","index/store_list",{
					 lat:this.lat,
					 lng:this.lng,
					 page:this.page,
					 pagesize:this.pagesize,
				},(res)=>{
				  if(res.code==200){
				  	
					if(e==1){
						this.list=res.data
					}else{
						 this.list = [...this.list, ...res.data];
					}
				  }else{
				     this.$u.toast(res.msg);
				  }
				})
			},
			address() {
				uni.openLocation({
					latitude: parseFloat(22.222),
					longitude: parseFloat(108.108),
					scale: 18
				});
			},
			to_list(id) {
				uni.navigateTo({
					url: '/pages/index/CarRental?store_id='+id
				})
			},
			xzsh(){
					  uni.navigateTo({
						  url: '/pages/index/CarRentals?type='+this.type,
						  events: {
							// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
							acceptDataFromOpenedPage: (data)=> {
				
												
												
									// this.contract_title=data.contract_name;
							},
						  },
						  success: (res) =>{
							// 通过eventChannel向被打开页面传送数据
							res.eventChannel.emit('acceptDataFromOpenerPage', { data: 'data from starter page' })
						  }
						})
			},
	// 		edit(item){
	// 			console.log(item)
			
	// 				// this.getOpenerEventChannel()是uni自带的一个方法,返回一个对象
	// 				const eventChannel = this.getOpenerEventChannel();
	// 				// 通过监听上个页面的uni.navigateTo的events中定义的事件传递参数
	// 				 eventChannel.emit('acceptDataFromOpenedPage', {
	
						
						
	// 					 });
	// 				 // 关闭当前页返回上一页并触发acceptDataFromOpenedPage事件
	// 				 uni.navigateBack({
	// 					delta: 1
	// 				 });
	// 		},


			// 分页
			queryList(pageNo, pageSize) {
				console.log(pageSize);
				// 此处请求仅为演示，请替换为自己项目中的请求
				this.$refs.paging.complete([{
						title: '同路仁官方店铺',
						tip: '营业中',
						time: '09:00 - 22:00',
						km: '0.5km',
						address: '南明区花果园购物中心2层'
					},
					{
						title: '同路仁官方店铺1',
						tip: '休息中',
						time: '09:00 - 22:00',
						km: '0.5km',
						address: '南明区花果园购物中心2层'
					},
					{
						title: '同路仁官方店铺2',
						tip: '休息中',
						time: '09:00 - 22:00',
						km: '0.5km',
						address: '南明区花果园购物中心2层'
					}
				]);
			}
		}
	};
</script>

<style lang="scss">
	.list {
		margin: 32rpx;
		padding: 32rpx 24rpx;
		background: #ffffff;
		border-radius: 24rpx;

		.title {
			font-size: 32rpx;
			font-weight: bold;
			margin-bottom: 12rpx;
		}

		.tip {
			color: #3377ff;
			font-size: 24rpx;
			margin-right: 24rpx;
		}

		.time {
			color: #999ca3;
			font-size: 24rpx;
		}

		.address {
			color: #666b75;
			font-size: 28rpx;
			margin-top: 12rpx;
		}

		.km {
			margin: 0 16rpx 0;
		}

		.iconImg {
			width: 32rpx;
			height: 32rpx;
			vertical-align: bottom;
		}
	}
</style>